﻿namespace BSU.Math.Geometry
{
    public class Point3D
    {
        private double _x;
        private double _y;
        private double _z;
        private bool _xIsDefined;
        private bool _yIsDefined;
        private bool _zIsDefined;

        public Point3D()
        {
        }
        public Point3D(double x, double y, double z)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public double InitialX { get; private set; }
        public double InitialY { get; private set; }
        public double InitialZ { get; private set; }

        public double X
        {
            get { return _x; }
            set
            {
                if (!_xIsDefined)
                {
                    _xIsDefined = true;
                    InitialX = value;
                }
                _x = value;
            }
        }
        public double Y
        {
            get { return _y; }
            set
            {
                if (!_yIsDefined)
                {
                    _yIsDefined = true;
                    InitialY = value;
                }
                _y = value;
            }
        }
        public double Z
        {
            get { return _z; }
            set
            {
                if (!_zIsDefined)
                {
                    _zIsDefined = true;
                    InitialZ = value;
                }
                _z = value;
            }
        }
        public Point3D SetBy(Point3D point)
        {
            X = point.X;
            Y = point.Y;
            Z = point.Z;
            return this;
        }

        public void ResetToInitial()
        {
            X = InitialX;
            Y = InitialY;
            Z = InitialZ;
        }
    }
}